/*
 * Created on 2005-4-29
 *
 * Copyright: Bluejay Networks Inc. 2005
 *
 * This software is the proprietary information of Bluejay Networks Inc. 
 * 
 * Use is subject to license terms.
 * 
 */
package com.ims.iaa;

import java.io.Serializable;
import java.net.Authenticator;

/**
 * @author ShengMengBai
 *
 * Save the proxy parameter
 */
public class ProxySetting implements Serializable{
    public String getHost(){
    	return m_sHost;
    }
    public void setHost(String sHost){
    	m_sHost = sHost;
    }
    public String getPort(){
    	return m_sPort;
    }
    public void setPort(String sPort){
    	m_sPort = sPort;
    }
    public String getUserName(){
    	return m_sUserName;
    }
    public void setUserName(String sUserName){
        if(sUserName != null){
        	m_sUserName = sUserName;
        }
        if(sUserName.toLowerCase().equals("anonymous")){
            m_sUserName = "";
        }
    }
    public String getPassword(){
    	return m_sPassword;
    }
    public void setPassword(String sPassword){
        if(sPassword != null){
            m_sPassword = sPassword;
        }
        if(m_sPassword.toLowerCase().equals("anonymous")){
            m_sPassword = "";
        }
    }
    public static void unProxy(){
		System.getProperties().put("proxySet", "false");
    }
    /**
     * Based on the proxy param, set current system properties to proxy
     */
    public void proxy(){
		System.getProperties().put("proxySet", "true");
		System.getProperties().put("proxyHost", m_sHost);
		System.getProperties().put("proxyPort", m_sPort);
		
		String sLog = "Change proxy setting:\r\n";
  		IaaUtil.printlog(sLog);
  		sLog = "\tHost: " + m_sHost + "    Port: " + m_sPort;
		
		if(!m_sPassword.equals("")){
			Authenticator.setDefault( new ProxyAuthenticator(m_sUserName, m_sPassword));
			sLog += "    UserName: " + m_sUserName + "    Password: " + m_sPassword;
		}
  		IaaUtil.printlog(sLog);
    }
    private String m_sHost = "";
    private String m_sPort = "";
    private String m_sUserName = "";
    private String m_sPassword = "";
}
